import { nextTick, ref, unref } from 'vue'
/* eslint-disable */
export function useTable(propsRef, tableElRef, emit, parent) {
    const sortInfo = ref({})
    const isShowTooltip = ref(false)
    const parentDom = ref(null) //表格的父元素dom

    function handleSortChange(column) {
        if (column.order) {
            sortInfo.value = {
                prop: column.prop,
                order: column.order
            }
            emit('sort-change', sortInfo.value)
        }
    }
    // 表头部重新渲染
    function renderHeader(index) {
        parentDom.value = document.getElementsByClassName(parent)
        nextTick(() => {
            let headerDom = parentDom.value[0].getElementsByClassName('el-table__header-wrapper')
            let th_head = headerDom[0].getElementsByClassName('cell')[index]
            let th_head_cell = th_head.getElementsByClassName('title_head')
            let parentWidth = th_head.offsetWidth;
            let contentWidth = th_head_cell[0].offsetWidth;
            if (contentWidth + 24 > parentWidth) {
                isShowTooltip.value = false
            } else {
                isShowTooltip.value = true
            }
        })

    }
    return {
        handleSortChange,
        isShowTooltip,
        renderHeader
    }
}

